import {
    UserProfilesAPI
} from '@/request/api'
export default {
    namespaced: true,
    state: {
        // 购物车数量
        cartTotal: 10,
        // 用户信息
        userInfo: {
            nickName: '--',
            coin: '100',
            headImg: require('../../assets/images/service.848ec511.png')
        }
    },
    mutations: {
        // 修改用户信息
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal,
                state.userInfo = payload.userInfo
        },
        // 初始化用户信息
        initUserInfo(state, payload) {
            state.cartTotal = 0;
            state.userInfo = {
                // 昵称
                nickName: '--',
                coin: '0',
                headImg: require('../../assets/images/service.848ec511.png'),
            }
        }
    },
    actions: {
        async asyncChangeupdateUserInfo(context) {
            // 发起请求
            let res = await UserProfilesAPI();
            context.commit('updateUserInfo', res.data)
        }
    },
}